package com.rs.qm.modules.member.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rs.qm.common.annotation.Log;
import com.rs.qm.common.annotation.RedisCache;
import com.rs.qm.common.utils.PageUtils;
import com.rs.qm.common.utils.Query;
import com.rs.qm.modules.member.dao.EnterpriseNameLibDao;
import com.rs.qm.modules.member.entity.EnterpriseNameLibEntity;
import com.rs.qm.modules.member.service.EnterpriseNameLibService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("enterpriseNameLibService")
public class EnterpriseNameLibServiceImpl extends ServiceImpl<EnterpriseNameLibDao, EnterpriseNameLibEntity> implements EnterpriseNameLibService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<EnterpriseNameLibEntity> page = this.selectPage(
                new Query<EnterpriseNameLibEntity>(params).getPage(),
                new EntityWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    @Log
    @RedisCache(cacheName = "ENTERPRISE-NAME-LIB-All")
    public Map<Long, EnterpriseNameLibEntity> queryAllNames() {
        Map<Long, EnterpriseNameLibEntity> namesMap = new HashMap<>();
        List<EnterpriseNameLibEntity> namesList = baseMapper.queryAllNames();
        namesList.stream().forEach(name -> {
            namesMap.put(name.getNameId(), name);
        });
        return namesMap;
    }

}